package com.sara.service;

import com.sara.dao.AdminDao;
import com.sara.entity.Admin;
import com.sara.exception.ServiceException;
import com.sara.util.Config;
import org.apache.commons.codec.digest.DigestUtils;

public class AdminService  {
    AdminDao adminDao = new AdminDao();


    public Admin login(String adminName, String password) throws  ServiceException{
        password = password + Config.ADMIN_PASSWORD_SALT;
        password = DigestUtils.md2Hex(password);
        System.out.println("password是:" + password);
        Admin admin = adminDao.findAdminByName(adminName);
        if(admin != null && password.equals(admin.getPassword())){
            return admin;
        }else {
            throw  new ServiceException("账户或密码错误");
        }
    }
}
